import taichi as ti

ti.init(arch=ti.cuda)
 
vec3f = ti.types.vector(3,ti.f32)
mat2f = ti.types.matrix(2,2,ti.f32)
ray = ti.types.struct(ro=vec3f,rd=vec3f,l=ti.f32)

@ti.kernel
def foo ():
    a = vec3f(0.0)
    print (a)
    d = vec3f(0.0,1.0,0.0)
    print(d)
    B = mat2f([[1.5,1.4],[1.3,1.2]])
    print("B=",B)
    r = ray(ro=a,rd=d,l=1)
    print("r.ro =",r.ro)
    print("r.rd =",r.rd)

foo()

#由于向量矩阵一类的结构用的比较多 可以直接使用太极内置定义
@ti.kernel
def bar():
    a = ti.Vector([0.0,0.0,0.0])
    print(a)
    print(a[1])
    d = ti.Vector([0.0,1.0,0.0])
    print(d)
    B = ti.Matrix([[1.5,1.4],[1.3,1.2]])
    print(B)
    print(B[1,0])
    r = ti.Struct(v1=a,v2=d,l=1)
    print("r.v1",r.v1)
    print("r.v2",r.v2)

bar()